package com.car.carmgr.controller;

import com.car.carmgr.util.ZXingCode;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;

@Controller
public class ZXingController {

    @RequestMapping("zXingInit")
    public String zxingInit(){
        return "zXingShow";
    }

    @RequestMapping("zXing")
    @ResponseBody
    public void zXing(OutputStream outputStream){
        BufferedImage image = ZXingCode.createZXingCodeToStream("徐浩的专属二维码儿", 300, 300);
        try {
            ImageIO.write(image,"JPEG",outputStream);
            outputStream.flush();
            outputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
